@{
    ViewData["Title"] = "车间管理";
}

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">车间编码</label>
                    <div class="layui-input-block">
                        <input type="text" name="Code" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">车间名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="Name" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="LAY-app-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>

        <div class="layui-card-body">
            <div style="padding-bottom: 10px;">
                <button class="layui-btn layuiadmin-btn-list" data-type="add">添加</button>
            </div>
            <table id="LAY-app-workshop-list" lay-filter="LAY-app-workshop-list"></table>
        </div>
    </div>
</div>

<script type="text/html" id="table-workshop-toolbar">
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
</script>

@section Scripts {
    <script>
        layui.use(['index', 'table', 'form'], function () {
            var $ = layui.$
                , table = layui.table
                , form = layui.form;

            table.render({
                elem: '#LAY-app-workshop-list'
                , url: '/ProductionSystem/Workshop/GetList'
                , cols: [[
                    { type: 'checkbox', fixed: 'left' }
                    , { field: 'code', title: '车间编码', width: 120 }
                    , { field: 'name', title: '车间名称', width: 120 }
                    , { field: 'description', title: '描述' }
                    , { field: 'createTime', title: '创建时间', width: 170 }
                    , { title: '操作', width: 150, align: 'center', fixed: 'right', toolbar: '#table-workshop-toolbar' }
                ]]
                , page: true
                , limit: 30
                , height: 'full-180'
            });

            //监听工具条
            table.on('tool(LAY-app-workshop-list)', function (obj) {
                var data = obj.data;
                if (obj.event === 'del') {
                    layer.confirm('确定删除此车间？', function (index) {
                        $.ajax({
                            url: '/ProductionSystem/Workshop/Delete/' + data.id,
                            type: 'DELETE',
                            success: function (res) {
                                if (res.code === 0) {
                                    obj.del();
                                    layer.close(index);
                                }
                                layer.msg(res.msg);
                            }
                        });
                    });
                } else if (obj.event === 'edit') {
                    layer.open({
                        type: 2
                        , title: '编辑车间'
                        , content: '/ProductionSystem/Workshop/Edit/' + data.id
                        , area: ['500px', '480px']
                        , btn: ['确定', '取消']
                        , yes: function (index, layero) {
                            var submit = layero.find('iframe').contents().find('#LAY-workshop-submit');
                            submit.click();
                        }
                    });
                }
            });

            //监听搜索
            form.on('submit(LAY-app-search)', function (data) {
                var field = data.field;
                table.reload('LAY-app-workshop-list', {
                    where: field
                });
            });
        });
    </script>
} 